﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace EasyTrader.Chart
{
    using PriceWaveList = List<EasyTrader.Wave.PriceWave>;
    using PricePointList = List<EasyTrader.Wave.PricePoint>;

    public partial class FutureMstBuySellChartFrm : System.Windows.Forms.Form
    {
        private EasyTrader.Signal.TotalSignalManager m_GSignalManager = null;
        public EasyTrader.Signal.TotalSignalManager GSignalManager
        {
            get { return m_GSignalManager; }
            set { m_GSignalManager = value; }
        }

        public FutureMstBuySellChartFrm()
        {
            InitializeComponent();
        }

        // Cybos Plus Data Set Member
        private ETDataSet m_CPDataSet = null;
        public EasyTrader.ETDataSet CPDataSet
        {
            get { return m_CPDataSet; }
            set { m_CPDataSet = value; }
        }
        private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
        private void InitTimer()
        {
            timer.Interval = GlobalVar.ChartRefreshInterval;
            timer.Tick += new EventHandler(OnTimerTick);
            timer.Start();
        }

        // 여기서 차트를 갱신해 준다.
        private void OnTimerTick(object sender, EventArgs e)
        {
            // 차트에 데이터를 대응시켜 준다.
            if (GlobalVar.OperationMode == GlobalVar.OperationModeNormal)
            {
                SetChartData();
                ShowCurValue();
                if (m_GSignalManager != null)
                {
                    PriceWaveList curWaveList = m_GSignalManager.ETHogaSignalManager.BuyWaveManager.ArragedWaveList;
                    SetBuyWaveOnChart(curWaveList);

                    curWaveList = m_GSignalManager.ETHogaSignalManager.SellWaveManager.ArragedWaveList;
                    SetSellWaveOnChart(curWaveList);

                    PricePointList pointList = m_GSignalManager.ETHogaSignalManager.BuyWaveManager.FilteredPointList;
                    SetBuyMidValOnChart(pointList);
                    pointList = m_GSignalManager.ETHogaSignalManager.SellWaveManager.FilteredPointList;
                    SetSellMidValOnChart(pointList);

                    double totalSquare = m_GSignalManager.TotalHogaSquare;
                    if (totalSquare != 0)
                    {
                        double pureBuySquare = Convert.ToDouble(m_GSignalManager.TotalBuySquare);
                        double pureSellSquare = Convert.ToDouble(m_GSignalManager.TotalSellSquare);
                        double buyS = totalSquare - pureSellSquare;
                        double sellS = totalSquare - pureBuySquare;
                        double buyRatio = (buyS / totalSquare);
                        double sellRatio = (sellS / totalSquare);
                        int buyVal = squareOccBar.Value = (int)(buyRatio * 100);
                        squareOccBar.LeftLabel = "매수 : " + buyVal.ToString() + "%";
                        squareOccBar.RightLabel = "매도 : " + (sellRatio * 100.0).ToString("F0") + "%";
                    }

                    double totalTime = Convert.ToDouble(m_GSignalManager.BuyTimeOcc) + Convert.ToDouble(m_GSignalManager.SellTimeOcc);
                    if (totalTime != 0)
                    {
                        double buyTimeRatio = (Convert.ToDouble(m_GSignalManager.BuyTimeOcc) / totalTime);
                        int buyVal = timeOccBar.Value = (int)(buyTimeRatio * 100);
                        timeOccBar.LeftLabel = "매수 : " + buyVal.ToString() + "%";
                        timeOccBar.RightLabel = "매도 : " + (100.0 - buyVal).ToString() + "%";
                    }
                    
                }
            }
            else
            {
                SetChartData(GlobalVar.SimulIndex);
                ShowCurValue(GlobalVar.SimulIndex);
                if (m_GSignalManager != null)
                {
                    PriceWaveList curWaveList = m_GSignalManager.ETHogaSignalManager.BuyWaveManager.ArragedWaveList;
                    SetBuyWaveOnChart(curWaveList);

                    curWaveList = m_GSignalManager.ETHogaSignalManager.SellWaveManager.ArragedWaveList;
                    SetSellWaveOnChart(curWaveList);

                    PricePointList pointList = m_GSignalManager.ETHogaSignalManager.BuyWaveManager.FilteredPointList;
                    SetBuyMidValOnChart(pointList);
                    pointList = m_GSignalManager.ETHogaSignalManager.SellWaveManager.FilteredPointList;
                    SetSellMidValOnChart(pointList);

                    
                    double totalSquare = m_GSignalManager.TotalHogaSquare;
                    if (totalSquare != 0)
                    {
                        double pureBuySquare = Convert.ToDouble(m_GSignalManager.TotalBuySquare);
                        double pureSellSquare = Convert.ToDouble(m_GSignalManager.TotalSellSquare);
                        double buyS = totalSquare - pureSellSquare;
                        double sellS = totalSquare - pureBuySquare;
                        double buyRatio = (buyS / totalSquare);
                        double sellRatio = (sellS / totalSquare);
                        int buyVal = squareOccBar.Value = (int)(buyRatio * 100);
                        squareOccBar.LeftLabel = "매수 : " + buyVal.ToString() + "%";
                        squareOccBar.RightLabel = "매도 : " + (sellRatio*100.0).ToString("F0") + "%";
                    }

                    double totalTime = Convert.ToDouble(m_GSignalManager.BuyTimeOcc) + Convert.ToDouble(m_GSignalManager.SellTimeOcc);
                    if (totalTime != 0)
                    {
                        double buyTimeRatio = (Convert.ToDouble(m_GSignalManager.BuyTimeOcc) / totalTime);
                        int buyVal = timeOccBar.Value = (int)(buyTimeRatio * 100);
                        timeOccBar.LeftLabel = "매수 : " + buyVal.ToString() + "%";
                        timeOccBar.RightLabel = "매도 : " + (100.0 - buyVal).ToString() + "%";
                    }
                    
                }
            }
            SetForecastingYOnChart();
        }

        private void SetBuyWaveOnChart(PriceWaveList a_WaveList)
        {
            // 먼저 이전에 모든 점들을 없애 준다.
            FutureMstBuySellChartCtrl.Series["매수파동"].Points.Clear();
            for (int i = 0; i < a_WaveList.Count; i++)
            {
                EasyTrader.Wave.PriceWave wave = a_WaveList[i];
                FutureMstBuySellChartCtrl.Series["매수파동"].Points.AddXY(wave.StartX, wave.StartY);
                // 파동은 마지막 점을 한번 더 넣어 준다.
                if (i == a_WaveList.Count - 1)
                {
                    FutureMstBuySellChartCtrl.Series["매수파동"].Points.AddXY(wave.EndX, wave.EndY);
                }
            }
        }

        private void SetSellWaveOnChart(PriceWaveList a_WaveList)
        {
            // 먼저 이전에 모든 점들을 없애 준다.
            FutureMstBuySellChartCtrl.Series["매도파동"].Points.Clear();
            for (int i = 0; i < a_WaveList.Count; i++)
            {
                EasyTrader.Wave.PriceWave wave = a_WaveList[i];
                FutureMstBuySellChartCtrl.Series["매도파동"].Points.AddXY(wave.StartX, wave.StartY);
                // 파동은 마지막 점을 한번 더 넣어 준다.
                if (i == a_WaveList.Count - 1)
                {
                    FutureMstBuySellChartCtrl.Series["매도파동"].Points.AddXY(wave.EndX, wave.EndY);
                }
            }
        }

        private void SetForecastingYOnChart()
        {
            if (m_GSignalManager == null)
                return;


            EasyTrader.Signal.ForecastingInfo foreInfo = GSignalManager.HogaBuyInfo;
            if (FutureMstBuySellChartCtrl.Series["매수건수예상가"] != null && foreInfo != null)
            {
                FutureMstBuySellChartCtrl.Series["매수건수예상가"].Points.Clear();
                FutureMstBuySellChartCtrl.Series["매수건수예상가"].Points.AddXY(foreInfo.StartX, foreInfo.StartY);
                FutureMstBuySellChartCtrl.Series["매수건수예상가"].Points.AddXY(foreInfo.EndX, foreInfo.EndY);
                txtBuyAngle.Text = "매수각도 : " + foreInfo.Angle.ToString("F2");
            }

            foreInfo = GSignalManager.HogaSellInfo;
            if (FutureMstBuySellChartCtrl.Series["매도건수예상가"] != null && foreInfo != null)
            {
                FutureMstBuySellChartCtrl.Series["매도건수예상가"].Points.Clear();
                FutureMstBuySellChartCtrl.Series["매도건수예상가"].Points.AddXY(foreInfo.StartX, foreInfo.StartY);
                FutureMstBuySellChartCtrl.Series["매도건수예상가"].Points.AddXY(foreInfo.EndX, foreInfo.EndY);
                txtSellAngle.Text = "매도각도 : " + foreInfo.Angle.ToString("F2");
            }
        }

        private void ShowCurValue()
        {
            // 데이터 셋 객체가 없으면 아무일도 하지 않는다.
            if (m_CPDataSet == null || GlobalVar.FutureMstDataDownloaded == false)
                return;

            FutureMstTable dataTable = m_CPDataSet.GetFutureMstTable();
            int rowCount = dataTable.GetRowCount();
            if (rowCount == 0)
                return;

            DataRow row = dataTable.Rows[rowCount - 1];
            double bidsValue = Convert.ToDouble(row["매수총호가건수"]);
            double asksValue = Convert.ToDouble(row["매도총호가건수"]);
            double delta = bidsValue - asksValue;
            string curTime = row["시각"].ToString();
            if (curTime != "0")
            {
                string minText = curTime.Substring(curTime.Length - 2, 2);
                string hourText = curTime.Substring(0, curTime.Length - 2);

                txtCurTime.Text = "현재시간 " + hourText + " : " + minText;
                txtCurPrice.Text = "매수건수 : " + bidsValue.ToString() + ", 매도건수 : " + asksValue.ToString() + "  건수차이 : " + delta.ToString();
            }
        }

        private void ShowCurValue(int a_CurIndex)
        {
            // 데이터 셋 객체가 없으면 아무일도 하지 않는다.
            if (m_CPDataSet == null)
                return;

            FutureMstTable dataTable = m_CPDataSet.GetFutureMstTable();
            int rowCount = dataTable.GetRowCount();
            if (rowCount == 0)
                return;
            if (rowCount - 1 < a_CurIndex)
                return;

            DataRow row = dataTable.Rows[a_CurIndex];
            double bidsValue = Convert.ToDouble(row["매수총호가건수"]);
            double asksValue = Convert.ToDouble(row["매도총호가건수"]);
            double delta = Math.Abs(bidsValue - asksValue);
            string curTime = row["시각"].ToString();
            if (curTime != "0")
            {
                string minText = curTime.Substring(curTime.Length - 2, 2);
                string hourText = curTime.Substring(0, curTime.Length - 2);

                txtCurTime.Text = "현재시간 " + hourText + " : " + minText;
                txtCurPrice.Text = "매수건수 : " + bidsValue.ToString() + ", 매도건수 : " + asksValue.ToString() + "  건수차이 : " + delta.ToString();
            }
        }

        private void SetBuyMidValOnChart(PricePointList a_PointList)
        {
            /*
            if (a_PointList.Count < 2)
                return;
            FutureMstBuySellChartCtrl.Series["매수중간가"].Points.Clear();
            for (int i = 0; i < a_PointList.Count; i++)
            {
                EasyTrader.Wave.PricePoint curPoint = a_PointList[i];
                FutureMstBuySellChartCtrl.Series["매수중간가"].Points.AddXY(i, curPoint.Y);
            }*/
            if (a_PointList.Count < GlobalVar.HogaValRefRange)
                return;
            FutureMstBuySellChartCtrl.DataManipulator.FinancialFormula(FinancialFormula.ExponentialMovingAverage, GlobalVar.MinHogaAveVal.ToString(), "매수건수", "매수중간가");
        }

        private void SetSellMidValOnChart(PricePointList a_PointList)
        {
            /*
            if (a_PointList.Count < 2)
                return;
            FutureMstBuySellChartCtrl.Series["매도중간가"].Points.Clear();
            for (int i = 0; i < a_PointList.Count; i++)
            {
                EasyTrader.Wave.PricePoint curPoint = a_PointList[i];
                FutureMstBuySellChartCtrl.Series["매도중간가"].Points.AddXY(i, curPoint.Y);
                FutureMstBuySellChartCtrl.Series["매수중간가"].Points[i].XValue = i;
            }
             * */
            if (a_PointList.Count < GlobalVar.HogaValRefRange)
                return;
            FutureMstBuySellChartCtrl.DataManipulator.FinancialFormula(FinancialFormula.ExponentialMovingAverage, GlobalVar.MinHogaAveVal.ToString(), "매도건수", "매도중간가");
        }
        private void SetChartData()
        {
            // 데이터 셋 객체가 없으면 아무일도 하지 않는다.
            if (m_CPDataSet == null)
                return;

            FutureMstBuySellChartCtrl.Series["매도건수"].Points.Clear();
            FutureMstBuySellChartCtrl.Series["매수건수"].Points.Clear();
            FutureMstTable dataTable = m_CPDataSet.GetFutureMstTable();
            double maxValue = -10000.0;
            double minValue = 10000.0;
            int rowCount = dataTable.GetRowCount();
            if (rowCount == 0)
                return;

            int minIndex = 0;
            int maxIndex = 0;
            double buyValue = 0;
            double sellValue = 0;
            for (int i = 0; i < rowCount; i++)
            {
                DataRow row = dataTable.Rows[i];
                try
                {
                    // 값이 없을 경우는 넘어 간다.
                    if (row["매수총호가건수"] == DBNull.Value)
                        continue;

                    buyValue = Convert.ToDouble(row["매수총호가건수"]);
                    sellValue = Convert.ToDouble(row["매도총호가건수"]);
                    FutureMstBuySellChartCtrl.Series["매수건수"].Points.AddXY(i, buyValue);
                    FutureMstBuySellChartCtrl.Series["매도건수"].Points.AddXY(i, sellValue);
                    FutureMstBuySellChartCtrl.Series["매수건수"].Points[i].XValue = i;
                    int hour = Convert.ToInt32(row["시각"]);
                    if (hour != 0)
                        FutureMstBuySellChartCtrl.Series["매수건수"].Points[i].AxisLabel = row["시각"].ToString();
                    else
                        FutureMstBuySellChartCtrl.Series["매수건수"].Points[i].AxisLabel = GlobalVar.HogaDayIndexToTime(i).ToString();
                    

                    if (buyValue != 0 && buyValue > maxValue)
                    {
                        maxValue = buyValue;
                        maxIndex = i;
                    }

                    if (sellValue != 0 && sellValue > maxValue)
                    {
                        maxValue = sellValue;
                        maxIndex = i;
                    }

                    if (sellValue != 0 && sellValue < minValue)
                    {
                        minValue = sellValue;
                        minIndex = i;
                    }

                    if (buyValue != 0 && buyValue < minValue)
                    {
                        minValue = buyValue;
                        minIndex = i;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }

            int valueHeight = (int)maxValue / 500;
            maxValue = (valueHeight + 1) * 500;
            //minValue = 0;

            if (maxValue >= minValue)
            {
                FutureMstBuySellChartCtrl.ChartAreas["BuySell"].AxisY.Minimum = minValue;
                FutureMstBuySellChartCtrl.ChartAreas["BuySell"].AxisY.Maximum = maxValue;
            }
        }

        private void SetChartData(int a_CurIndex)
        {
            // 데이터 셋 객체가 없으면 아무일도 하지 않는다.
            if (m_CPDataSet == null)
                return;

            FutureMstBuySellChartCtrl.Series["매도건수"].Points.Clear();
            FutureMstBuySellChartCtrl.Series["매수건수"].Points.Clear();
            FutureMstTable dataTable = m_CPDataSet.GetFutureMstTable();
            double maxValue = -10000.0;
            double minValue = 10000.0;
            int rowCount = dataTable.GetRowCount();
            if (rowCount == 0)
                return;
            if (rowCount - 1 < a_CurIndex)
                return;

            int minIndex = 0;
            int maxIndex = 0;
            double buyValue = 0;
            double sellValue = 0;
            for (int i = 0; i <= a_CurIndex; i++)
            {
                DataRow row = dataTable.Rows[i];
                try
                {
                    // 값이 없을 경우는 넘어 간다.
                    if (row["매수총호가건수"] == DBNull.Value)
                        continue;

                    buyValue = Convert.ToDouble(row["매수총호가건수"]);
                    sellValue = Convert.ToDouble(row["매도총호가건수"]);
                    FutureMstBuySellChartCtrl.Series["매수건수"].Points.AddXY(i, buyValue);
                    FutureMstBuySellChartCtrl.Series["매도건수"].Points.AddXY(i, sellValue);
                    FutureMstBuySellChartCtrl.Series["매수건수"].Points[i].XValue = i;
                    int hour = Convert.ToInt32(row["시각"]);
                    if (hour != 0)
                        FutureMstBuySellChartCtrl.Series["매수건수"].Points[i].AxisLabel = row["시각"].ToString();
                    else
                        FutureMstBuySellChartCtrl.Series["매수건수"].Points[i].AxisLabel = GlobalVar.HogaDayIndexToTime(i).ToString();


                    if (buyValue != 0 && buyValue > maxValue)
                    {
                        maxValue = buyValue;
                        maxIndex = i;
                    }

                    if (sellValue != 0 && sellValue > maxValue)
                    {
                        maxValue = sellValue;
                        maxIndex = i;
                    }

                    if (sellValue != 0 && sellValue < minValue)
                    {
                        minValue = sellValue;
                        minIndex = i;
                    }

                    if (buyValue != 0 && buyValue < minValue)
                    {
                        minValue = buyValue;
                        minIndex = i;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }

            int valueHeight = (int)maxValue / 500;
            maxValue = (valueHeight + 1) * 500;
            //minValue = 0;

            if (maxValue >= minValue)
            {
                FutureMstBuySellChartCtrl.ChartAreas["BuySell"].AxisY.Minimum = minValue;
                FutureMstBuySellChartCtrl.ChartAreas["BuySell"].AxisY.Maximum = maxValue;
            }
        }

        public FutureMstBuySellChartFrm(ETDataSet a_DataSet)
        {
            InitializeComponent();
            m_CPDataSet = a_DataSet;
            InitControl();
        }

        private void InitControl()
        {
            cbFore.Checked = true;
            cbBuyMidVal.Checked = true;
            cbSellMidVal.Checked = true;
            cbPrice.Checked = true;
            cbBuy.Checked = true;
            cbSell.Checked = true;
            FutureMstBuySellChartCtrl.Series["매수건수"].ToolTip = "#VALX : #VAL";
            FutureMstBuySellChartCtrl.Series["매도건수"].ToolTip = "#VALX : #VAL";
            FutureMstBuySellChartCtrl.Series["매수건수예상가"].ToolTip = "#VALX : #VAL";
            FutureMstBuySellChartCtrl.Series["매도건수예상가"].ToolTip = "#VALX : #VAL";
            FutureMstBuySellChartCtrl.Series["매수중간가"].ToolTip = "#VALX : #VAL";
            FutureMstBuySellChartCtrl.Series["매도중간가"].ToolTip = "#VALX : #VAL";
            FutureMstBuySellChartCtrl.Series["매수파동"].ToolTip = "#VALX : #VAL";
            FutureMstBuySellChartCtrl.Series["매도파동"].ToolTip = "#VALX : #VAL";
            cbBuyWave.Checked = true;
            cbSellWave.Checked = true;
        }

        private void InitChart()
        {
            FutureMstBuySellChartCtrl.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(211)), ((System.Byte)(223)), ((System.Byte)(240)));
            FutureMstBuySellChartCtrl.BackSecondaryColor = System.Drawing.Color.White;
            FutureMstBuySellChartCtrl.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
            FutureMstBuySellChartCtrl.BorderlineColor = System.Drawing.Color.FromArgb(((System.Byte)(26)), ((System.Byte)(59)), ((System.Byte)(105)));
            FutureMstBuySellChartCtrl.BorderlineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            FutureMstBuySellChartCtrl.BorderlineWidth = 2;
            FutureMstBuySellChartCtrl.BorderSkin.SkinStyle = System.Windows.Forms.DataVisualization.Charting.BorderSkinStyle.Emboss;

            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].AxisX.MajorGrid.Interval = 20;
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].AxisX.Interval = 20;
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].AxisY.MajorGrid.Interval = 400;
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].AxisY.MinorGrid.Interval = 200;
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].AxisY.Interval = 200;

            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].Area3DStyle.IsClustered = true;
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].Area3DStyle.Perspective = 10;
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].Area3DStyle.IsRightAngleAxes = false;
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].Area3DStyle.WallWidth = 0;
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].Area3DStyle.Inclination = 15;
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].Area3DStyle.Rotation = 10;
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].AxisX.IsLabelAutoFit = true;
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].AxisX.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].AxisX.LabelStyle.IsEndLabelVisible = false;
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].AxisX.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].AxisX.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].AxisY.IsLabelAutoFit = true;
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].AxisY.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].AxisY.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].AxisY.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].AxisY.IsStartedFromZero = false;
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].AxisY.MinorGrid.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].AxisY.MinorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.DashDot;

            //FutureMstBuySellChartCtrl.ChartAreas["Price"].AxisY.LabelAutoFitMaxFontSize;
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].BackColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(165)), ((System.Byte)(191)), ((System.Byte)(228)));
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].BackSecondaryColor = System.Drawing.Color.White;
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].BorderColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].Position.Auto = true;
            //FutureMstBuySellChartCtrl.ChartAreas["Price"].Position.Height = 80F;
            //FutureMstBuySellChartCtrl.ChartAreas["Price"].Position.Width = 80F;
            //FutureMstBuySellChartCtrl.ChartAreas["Price"].Position.X = 5F;
            //FutureMstBuySellChartCtrl.ChartAreas["Price"].Position.Y = 10F;
            FutureMstBuySellChartCtrl.ChartAreas["BuySell"].ShadowColor = System.Drawing.Color.Transparent;
            
            //FutureMstBuySellChartCtrl.Series["지수"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
             

            //FutureMstBuySellChartCtrl.Series[0]["PriceUpColor"] = "blue";
            //FutureMstBuySellChartCtrl.Series[0]["PriceDownColor"] = "Red";
            //FutureMstBuySellChartCtrl.ChartAreas["Price"].AxisX.LabelStyle.IsEndLabelVisible = true;
            //FutureMstBuySellChartCtrl.ChartAreas["Price"].AxisX.IsMarginVisible = true;
            //FutureMstBuySellChartCtrl.ChartAreas["Price"].AxisY.LabelStyle.IsEndLabelVisible = true;
            //FutureMstBuySellChartCtrl.ChartAreas["Price"].AxisY.IsMarginVisible = true;
            //FutureMstBuySellChartCtrl.Series[0].Color = Color.Red;
            //DataPointCustomProperties aa = FutureMstBuySellChartCtrl.Series[0]["PriceUpColor"];
            //System.Windows.Forms.DataVisualization.Charting.StripLine stripLine = new System.Windows.Forms.DataVisualization.Charting.StripLine();
            //stripLine.Interval = 0;
            //stripLine.IntervalOffset = GlobalVar.MinBuySell;
            //stripLine.BackColor = Color.Black;
            //stripLine.StripWidth = 1.0;
            //stripLine.Text = "임계선";
            //stripLine.TextAlignment = StringAlignment.Near;
            //FutureMstBuySellChartCtrl.ChartAreas[0].AxisY.StripLines.Add(stripLine);
        }

        private void FutureMstBuySellChart_Load(object sender, EventArgs e)
        {
            InitChart();
            InitTimer();
        }

        private void FutureMstBuySellChart_FormClosing(object sender, FormClosingEventArgs e)
        {
            timer.Stop();
        }

        private void cbFore_CheckedChanged(object sender, EventArgs e)
        {
            if (cbFore.Checked == true)
            {
                FutureMstBuySellChartCtrl.Series["매수건수예상가"].Enabled = true;
                FutureMstBuySellChartCtrl.Series["매도건수예상가"].Enabled = true;
            }
            else
            {
                FutureMstBuySellChartCtrl.Series["매수건수예상가"].Enabled = false;
                FutureMstBuySellChartCtrl.Series["매도건수예상가"].Enabled = false;
            }
        }

        private void cbBuyWave_CheckedChanged(object sender, EventArgs e)
        {
            if (cbBuyWave.Checked == true)
            {
                FutureMstBuySellChartCtrl.Series["매수파동"].Enabled = true;
            }
            else
            {
                FutureMstBuySellChartCtrl.Series["매수파동"].Enabled = false;
            }
        }

        private void cbSellWave_CheckedChanged(object sender, EventArgs e)
        {
            if (cbSellWave.Checked == true)
            {
                FutureMstBuySellChartCtrl.Series["매도파동"].Enabled = true;
            }
            else
            {
                FutureMstBuySellChartCtrl.Series["매도파동"].Enabled = false;
            }
        }

        private void cbBuyMidVal_CheckedChanged(object sender, EventArgs e)
        {
            if (cbBuyMidVal.Checked == true)
            {
                FutureMstBuySellChartCtrl.Series["매수중간가"].Enabled = true;
            }
            else
            {
                FutureMstBuySellChartCtrl.Series["매수중간가"].Enabled = false;
            }
        }

        private void cbSellMidVal_CheckedChanged(object sender, EventArgs e)
        {
            if (cbSellMidVal.Checked == true)
            {
                FutureMstBuySellChartCtrl.Series["매도중간가"].Enabled = true;
            }
            else
            {
                FutureMstBuySellChartCtrl.Series["매도중간가"].Enabled = false;
            }
        }

        private void cbPrice_CheckedChanged(object sender, EventArgs e)
        {
            if (cbPrice.Checked == true)
            {
                FutureMstBuySellChartCtrl.Series["매도건수"].Enabled = true;
                FutureMstBuySellChartCtrl.Series["매수건수"].Enabled = true;
            }
            else
            {
                FutureMstBuySellChartCtrl.Series["매도건수"].Enabled = false;
                FutureMstBuySellChartCtrl.Series["매수건수"].Enabled = false;
            }
        }

        private void cbBuy_CheckedChanged(object sender, EventArgs e)
        {
            if (cbBuy.Checked == true)
            {
                FutureMstBuySellChartCtrl.Series["매수건수"].Enabled = true;
            }
            else
            {
                FutureMstBuySellChartCtrl.Series["매수건수"].Enabled = false;
            }
        }

        private void cbSell_CheckedChanged(object sender, EventArgs e)
        {
            if (cbSell.Checked == true)
            {
                FutureMstBuySellChartCtrl.Series["매도건수"].Enabled = true;
            }
            else
            {
                FutureMstBuySellChartCtrl.Series["매도건수"].Enabled = false;
            }
        }
    }
}
